package com.zut.controller.shop;

import com.alibaba.druid.util.StringUtils;
import com.zut.pojo.Shop;
import com.zut.service.ShopService;
import com.zut.service.impl.ShopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalTime;

/**
 * @author 张晨
 * @date 2024/9/7 9:25
 * @desc
 */
@WebServlet("/shop/add")
public class ShopAddController extends HttpServlet {
    private ShopService ShopService = new ShopServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer businessId = Integer.parseInt(req.getParameter("businessId"));

        // if (StringUtils.isEmpty(businessId)){
        //     req.getRequestDispatcher("/business/select").forward(req,resp);
        //     return;
        // }


        String shopName = req.getParameter("shopName");
        String shopAddress = req.getParameter("shopAddress");
        String shopExplain = req.getParameter("shopExplain");
        String shopImg = req.getParameter("shopImg");
        Integer shopCategoryId =Integer.parseInt( req.getParameter("shopCategoryId"));
        BigDecimal startPrice = new BigDecimal(req.getParameter("startPrice"));
        BigDecimal deliveryPrice = new BigDecimal(req.getParameter("deliveryPrice"));
        String remark = req.getParameter("remark");
        LocalTime startTime = LocalTime.parse(req.getParameter("startTime"));
        LocalTime endTime = LocalTime.parse(req.getParameter("endTime"));

        Shop shop = new Shop();

        shop.setBusinessId(businessId);
        shop.setShopName(shopName);
        shop.setShopAddress(shopAddress);
        shop.setShopExplain(shopExplain);
        shop.setShopImg(shopImg);
        shop.setShopCategoryId(shopCategoryId);
        shop.setStartPrice(startPrice);
        shop.setDeliveryPrice(deliveryPrice);
        shop.setRemark(remark);
        shop.setStartTime(startTime);
        shop.setEndTime(endTime);

        Integer count = ShopService.addShop(shop);


        resp.getWriter().write(count+"");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
